package com.dkakunsi.monev.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dkakunsi.monev.dao.KegiatanDao;
import com.dkakunsi.monev.entity.Indikator;
import com.dkakunsi.monev.entity.Kegiatan;
import com.dkakunsi.monev.entity.Program;
import com.dkakunsi.monev.entity.Realisasi;
import com.dkakunsi.monev.report.EvaluasiKegiatanReportModel;
import com.dkakunsi.monev.report.InstansiReportModel;
import com.dkakunsi.monev.report.MonitoringKegiatanReportModel;
import com.dkakunsi.monev.report.ProgramReportModel;
import com.dkakunsi.monev.util.MonevDataException;

@Service("reportService")
public class ReportService {
	@Autowired private KegiatanDao kegiatanDao;
	@Autowired private RealisasiService realisasiService;
	@Autowired private IndikatorService indikatorService;
	
	public List<InstansiReportModel> get(String instansiTerkait, int tahunAnggaran) throws MonevDataException {
		List<InstansiReportModel> ls = new ArrayList<>();
		for(Kegiatan k : kegiatanDao.get(instansiTerkait, tahunAnggaran)) {
			InstansiReportModel e = new InstansiReportModel(k);
			ls.add(e);
		}

		return ls;
	}
	
	public List<ProgramReportModel> get(Program program, int tahunAnggaran) throws MonevDataException {
		List<ProgramReportModel> ls = new ArrayList<>();
		for(Kegiatan k : kegiatanDao.get(program, tahunAnggaran)) {
			ProgramReportModel e = new ProgramReportModel(k);
			ls.add(e);
		}
		
		return ls;
	}
	
	public List<MonitoringKegiatanReportModel> getMonitoringKegiatan(Kegiatan k, int tahun) throws MonevDataException {
		List<MonitoringKegiatanReportModel> ls = new ArrayList<>();
		for(Realisasi r : realisasiService.getRealisasi(k)) {
			MonitoringKegiatanReportModel e = new MonitoringKegiatanReportModel(r);
			ls.add(e);
		}
		
		return ls;
	}
	
	public List<EvaluasiKegiatanReportModel> getEvaluasiKegiatan(Kegiatan k, int tahun) throws MonevDataException {
		List<EvaluasiKegiatanReportModel> ls = new ArrayList<>();
		for(Indikator i : indikatorService.get(k)) {
			EvaluasiKegiatanReportModel e = new EvaluasiKegiatanReportModel(i);
			ls.add(e);
		}
		
		return ls;
	}
}
